/**
* @project admin-go-api
* @name sysLoginInfo
* @descriptions 登录日志控制层
* @author 寒锋
* @date 2023-12-22 14:37:37
 */

package controller

import (
	"admin-go-api/api/entity"
	"admin-go-api/api/service"
	"admin-go-api/common/response"
	"admin-go-api/constants"
	"fmt"
	"github.com/gin-gonic/gin"
	"strconv"
)

// GetSysLoginInfoList
// @Summary 登录日志列表接口
// @Produce json
// @Description 登录日志列表接口
// @Security ApiKeyAuth
// @Param pageNum query int false "当前页"
// @Param pageSize query int false "每页显示数量"
// @Param username query string false "用户名"
// @Param loginStatus query int false "登录状态（1-成功 2-失败）"
// @Param BeginTime query string false "开始时间"
// @Param EndTime query string false "结束时间"
// @Success 200 {object} response.Result
// @Router /api/sysLoginInfo/index [get]
func GetSysLoginInfoList(c *gin.Context) {
	PageNum, _ := strconv.Atoi(c.DefaultQuery("pageNum", "1"))
	PageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "10"))
	Username := c.DefaultQuery("username", "")
	LoginStatus, _ := strconv.Atoi(c.DefaultQuery("loginStatus", "0"))
	BeginTime := c.DefaultQuery("beginTime", "")
	EndTime := c.DefaultQuery("endTime", "")
	service.SysLoginInfoService().GetSysLoginInfoList(c, PageNum, PageSize, LoginStatus, Username, BeginTime, EndTime)
}

// DeleteSysLoginInfoById
// @Summary 删除登录日志接口
// @Produce json
// @Description 删除登录日志接口
// @Security ApiKeyAuth
// @Param data body entity.SysLoginInfoIdDto true "data"
// @Success 200 {object} response.Result
// @Router /api/sysLoginInfo/destroy [delete]
func DeleteSysLoginInfoById(c *gin.Context) {
	var dto entity.SysLoginInfoIdDto
	err := c.ShouldBind(&dto)
	if err != nil {
		response.Failed(c, int(constants.ApiCode.FAILED), fmt.Sprintf("参数错误（%s）", err.Error()))
	}
	service.SysLoginInfoService().DeleteSysLoginInfoById(c, dto)
}

// BatchDeleteSysLoginInfo
// @Summary 批量删除登录日志接口
// @Produce json
// @Description 批量删除登录日志接口
// @Security ApiKeyAuth
// @Param data body entity.DelSysLoginInfoDto true "data"
// @Success 200 {object} response.Result
// @Router /api/sysLoginInfo/batchDestroy [delete]
func BatchDeleteSysLoginInfo(c *gin.Context) {
	var dto entity.DelSysLoginInfoDto
	err := c.ShouldBind(&dto)
	if err != nil {
		response.Failed(c, int(constants.ApiCode.FAILED), fmt.Sprintf("参数错误（%s）", err.Error()))
	}
	service.SysLoginInfoService().BatchDeleteSysLoginInfo(c, dto)
}

// CleanSysLoginInfo
// @Summary 清空登录日志接口
// @Produce json
// @Description 清空登录日志接口
// @Security ApiKeyAuth
// @Success 200 {object} response.Result
// @Router /api/sysLoginInfo/clean [delete]
func CleanSysLoginInfo(c *gin.Context) {
	service.SysLoginInfoService().CleanSysLoginInfo(c)
}
